namespace TheCup.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    
    using Microsoft.AspNet.Identity.EntityFramework;

    internal sealed class Configuration : DbMigrationsConfiguration<ApplicationDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            ContextKey = "TheCup.ApplicationDbContext";
        }

        protected override void Seed(TheCup.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
            var admin = new IdentityRole("Admin");
            var user = new IdentityRole("User");
            // people that self register
            var visitor = new IdentityRole("Visitor");
            context.Roles.AddOrUpdate(visitor, user, admin);
            
            var a1 = new IdentityUserRole { UserId = "dj", RoleId = "Admin"};
            var a2 = new IdentityUserRole { UserId = "sg", RoleId = "Admin"};
            
            var dj = new ApplicationUser { UserName = "dj", Email = "brunis@gmail.com", EmailConfirmed = true };
            var sg = new ApplicationUser { UserName = "sg", Email = "sg@granfeldt.dk", EmailConfirmed = true };
            dj.Roles.Add(a1);
            sg.Roles.Add(a2);
            context.Users.AddOrUpdate(dj, sg);

            context.SaveChanges();
        }
    }
}
